# -*- encoding=utf8 -*-
"""
RedFlag-TC0000115  （拍摄进入装饰页）特效交互用例
①取消特效场景
④多次添加特效场景
⑤多次添加特效到达各种阈值场景
⑥特效替换场景
⑦特效删除场景
⑧特效保存场景
"""
__author__ = "ldm"

import sys
import os

# 获取当前脚本所在目录.py
current_dir = os.path.dirname(os.path.abspath(__file__))
# 获取上级目录.air
parent_dir = os.path.dirname(current_dir)
# 获取上级目录air
grandparent_dir = os.path.dirname(parent_dir)
# 获取和air目录平级的conf、testcase目录路径
conf_dir = os.path.join(grandparent_dir, 'conf')
testcase_dir = os.path.join(grandparent_dir, 'testcase')
# 将conf、testcase目录添加到sys.path
sys.path.append(conf_dir)
sys.path.append(testcase_dir)

from PageFunction import CameraVideoShooter
from elements import *

auto_setup(__file__)
shooter = CameraVideoShooter()

log("--------------------------------取消特效场景--------------------------------------")
"""
拍摄进入装饰页
点击特效
点击取消
断言
"""

shooter.enter_photography_decoration_page()
shooter.click_element(decoration_page_special_effects)
shooter.click_element(decoration_page_special_effects_cancel)
shooter.assert_element_exists(decoration_page_return_button, "断言失败，预期元素并未出现")


log("--------------------------------多次添加特效场景--------------------------------------")
"""
拍摄进入装饰页
点击特效
点击取消
断言
"""

shooter.click_element(decoration_page_special_effects)
shooter.click_element(decoration_page_special_effects_add)
shooter.click_element(decoration_page_special_effects_panel_choice[1])
sleep(2.0)
shooter.click_element(decoration_page_special_effects_panel_confirm)
shooter.click_element(decoration_page_special_effects_add)
shooter.click_element(decoration_page_special_effects_panel_choice[2])
sleep(2.0)
shooter.click_element(decoration_page_special_effects_panel_confirm)
shooter.click_element(decoration_page_special_effects_add)
shooter.click_element(decoration_page_special_effects_panel_choice[3])
sleep(2.0)
shooter.click_element(decoration_page_special_effects_panel_confirm)


log("--------------------------------多次添加特效到达各种阈值场景--------------------------------------")
"""
在视频底部继续添加特效
断言toast
断言元素
滑动视频条
"""

shooter.click_element(decoration_page_special_effects_add)
shooter.assert_toast_popup(decoration_page_special_effects_add,r"tpl1758076821183.png","断言失败，未找到toast弹窗")
shooter.assert_element_not_exists(decoration_page_special_effects_panel_cancel,"断言失败，预期元素出现说明进入了特效页面")
shooter.swipe_screen((0.1,0.9),(0.7,0.9),0.5,3)
shooter.click_element(decoration_page_special_effects_add)
shooter.click_element(decoration_page_special_effects_panel_choice[1])
shooter.click_element(decoration_page_special_effects_panel_confirm)
shooter.click_element(decoration_page_special_effects_add)
shooter.click_element(decoration_page_special_effects_panel_choice[2])
shooter.click_element(decoration_page_special_effects_panel_confirm)
shooter.click_element(decoration_page_special_effects_add)
shooter.assert_toast_popup(decoration_page_special_effects_add,r"tpl1758079458572.png","断言失败，未找到toast弹窗")
shooter.assert_element_not_exists(decoration_page_special_effects_panel_cancel,"断言失败，预期元素出现说明进入了特效页面")


log("--------------------------------特效替换场景--------------------------------------")
"""
点击替换
选择一个特效
点击✓
断言
"""

shooter.click_element(decoration_page_special_effects_panel_replace)
shooter.click_element(decoration_page_special_effects_panel_choice[3])
shooter.click_element(decoration_page_special_effects_panel_confirm)
shooter.assert_image_exists(r"tpl1758091258713.png", "断言失败，预期图片并未出现，替换失败", record_pos=(-0.092, 0.836), resolution=(1224, 2700))


log("--------------------------------特效删除场景--------------------------------------")
"""
点击删除
断言
"""

shooter.click_element(decoration_page_special_effects_panel_delete)
shooter.assert_image_not_exists(r"tpl1758091258713.png", "断言失败，预期图片并未出现，替换失败", record_pos=(-0.092, 0.836), resolution=(1224, 2700))

log("--------------------------------特效保存场景--------------------------------------")
"""
滑动操作
截屏
点击保存
点击特效
断言
"""

shooter.swipe_screen((0.1,0.9),(0.7,0.9),0.5,2)
photo1  = shooter.capture_screenshot("TC0000115A.png")
shooter.click_element(decoration_page_special_effects_confirm)
shooter.click_element(decoration_page_special_effects)
photo2 = shooter.capture_screenshot("TC0000115B.png")
shooter.assert_images_equal(photo1, photo2, "断言失败，图片比对失败",threshold=0.95)

# 关闭应用
stop_app(UGC_package_name)